//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.live.tool.commons;

import java.math.BigDecimal;

public class IConvert {
    public IConvert() {
    }

    public static Double doubleRoundHalfUp(Double d, int precision) {
        return doubleRound(d, precision, 4);
    }

    public static Double doubleRoundDown(Double d, int precision) {
        return doubleRound(d, precision, 1);
    }

    public static Double doubleRound(Double d, int precision, int roundType) {
        return (new BigDecimal(d)).setScale(precision, roundType).doubleValue();
    }

    public static String numToCnUpper(int si) {
        String[] aa = new String[]{"", "十", "百", "千", "万", "十万", "百万", "千万", "亿", "十亿"};
        String[] bb = new String[]{"一", "二", "三", "四", "五", "六", "七", "八", "九"};
        char[] ch = String.valueOf(si).toCharArray();
        int maxindex = ch.length;
        StringBuffer sb = new StringBuffer();
        int i;
        int j;
        if (maxindex == 2) {
            i = maxindex - 1;

            for(j = 0; i >= 0; ++j) {
                if (ch[j] != '0') {
                    if (j == 0 && ch[j] == '1') {
                        sb.append(aa[i]);
                    } else {
                        sb.append(bb[ch[j] - 49] + aa[i]);
                    }
                }

                --i;
            }
        } else {
            i = maxindex - 1;

            for(j = 0; i >= 0; ++j) {
                if (ch[j] != '0') {
                    sb.append(bb[ch[j] - 49] + aa[i]);
                }

                --i;
            }
        }

        return sb.toString();
    }

    public static Long[] string2LongArray(String ids) {
        try {
            String[] idsArray = ids.split(",");
            Long[] longArray = new Long[idsArray.length];

            for(int i = 0; i < idsArray.length; ++i) {
                longArray[i] = string2long(idsArray[i].trim());
            }

            return longArray;
        } catch (Exception var4) {
            var4.printStackTrace();
            return null;
        }
    }

    public static String int2string(Integer i) {
        return i == null ? null : i.toString();
    }

    public static String object2string(Object obj) {
        return ICommons.isNullOrEmpty(obj) ? "" : obj.toString();
    }

    public static Short int2short(Integer i) {
        if (i == null) {
            return null;
        } else {
            try {
                return i.shortValue();
            } catch (Exception var2) {
                return null;
            }
        }
    }

    public static Double int2double(Integer i) {
        if (i == null) {
            return 0.0D;
        } else {
            try {
                return i.doubleValue();
            } catch (Exception var2) {
                return 0.0D;
            }
        }
    }

    public static Long int2long(Integer i) {
        if (i == null) {
            return 0L;
        } else {
            try {
                return i.longValue();
            } catch (Exception var2) {
                return 0L;
            }
        }
    }

    public static Integer integerFormat(Integer i) {
        return i == null ? 0 : i;
    }

    public static Long longFormat(Long l) {
        return l == null ? 0L : l;
    }

    public static Double doubleFormat(Double d) {
        return d == null ? 0.0D : d;
    }

    public static Integer long2int(Long l) {
        if (ICommons.isNullOrEmpty(l)) {
            return 0;
        } else {
            try {
                return Long.valueOf(l).intValue();
            } catch (Exception var2) {
                var2.printStackTrace();
                return 0;
            }
        }
    }

    public static Double long2double(Long l) {
        if (ICommons.isNullOrEmpty(l)) {
            return 0.0D;
        } else {
            try {
                return l.doubleValue();
            } catch (Exception var2) {
                var2.printStackTrace();
                return 0.0D;
            }
        }
    }

    public static Integer double2int(Double d) {
        if (ICommons.isNullOrEmpty(d)) {
            return 0;
        } else {
            try {
                return Double.valueOf(d).intValue();
            } catch (Exception var2) {
                return 0;
            }
        }
    }

    public static Float double2float(Double d) {
        if (ICommons.isNullOrEmpty(d)) {
            return 0.0F;
        } else {
            try {
                return Double.valueOf(d).floatValue();
            } catch (Exception var2) {
                return 0.0F;
            }
        }
    }

    public static Integer float2int(Float f) {
        if (ICommons.isNullOrEmpty(f)) {
            return 0;
        } else {
            try {
                return f.intValue();
            } catch (Exception var2) {
                return 0;
            }
        }
    }

    public static Float object2float(Object obj) {
        if (ICommons.isNullOrEmpty(obj)) {
            return 0.0F;
        } else {
            try {
                return Float.parseFloat(object2string(obj));
            } catch (Exception var2) {
                var2.printStackTrace();
                return 0.0F;
            }
        }
    }

    public static Boolean isNumeric(String s) {
        try {
            Double.parseDouble(s);
            return true;
        } catch (Exception var2) {
            return false;
        }
    }

    public static Double string2double(String s) {
        if (ICommons.isNullOrEmpty(s)) {
            return 0.0D;
        } else {
            try {
                return Double.parseDouble(s);
            } catch (Exception var2) {
                return 0.0D;
            }
        }
    }

    public static Integer string2int(String s) {
        if (ICommons.isNullOrEmpty(s)) {
            return 0;
        } else {
            try {
                return Integer.parseInt(s);
            } catch (Exception var2) {
                var2.printStackTrace();
                return 0;
            }
        }
    }

    public static Integer object2int(Object obj) {
        if (ICommons.isNullOrEmpty(obj)) {
            return 0;
        } else {
            try {
                return Integer.parseInt(obj.toString());
            } catch (Exception var2) {
                return 0;
            }
        }
    }

    public static Long object2long(Object obj) {
        if (ICommons.isNullOrEmpty(obj)) {
            return 0L;
        } else {
            try {
                return Long.parseLong(obj.toString().trim());
            } catch (Exception var2) {
                return 0L;
            }
        }
    }

    public static Long string2long(String s) {
        if (ICommons.isNullOrEmpty(s)) {
            return 0L;
        } else {
            try {
                return Long.parseLong(s);
            } catch (Exception var2) {
                return 0L;
            }
        }
    }

    public static Double object2double(Object obj) {
        if (ICommons.isNullOrEmpty(obj)) {
            return 0.0D;
        } else {
            try {
                return Double.parseDouble(obj.toString());
            } catch (Exception var2) {
                var2.printStackTrace();
                return 0.0D;
            }
        }
    }

    public static Boolean string2boolean(String s) {
        return !ICommons.isNullOrEmpty(s) && s.trim().toLowerCase().equals("true") ? true : false;
    }
}
